<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%-- <%@include file="../../common/taglib/taglib.jsp"%> --%>
<form id="pagerForm" method="post" action="${baseURL }/trade/listPaymentRecord">
	<%@include file="../common/pageParameter.jsp"%>
</form>
<div class="pageHeader">
	<form rel="pagerForm" onsubmit="return navTabSearch(this);" action="${baseURL }/trade/listPaymentRecord" method="post">
		<div class="searchBar">
			<table class="searchContent">
				<tr >
					<td>
					<label style="margin-left: -4px;">商户编号：  </label>
					<input style="margin-left: -48px; margin-right: 20px" type="text" name="merchant.userNo" size="25" maxlength="128" class="readonly" value="${paymentOrderQueryParam.merchantNo}" />
					<a style="position: relative;left: 160px;" class="btnLook" href="${baseURL}/user/info/lookupList" lookupGroup="merchant">选择商户</a>
					&nbsp;&nbsp;
					商户订单号：
					<input type="text" id="merchantOrderNo" name="merchantOrderNo" value="${paymentOrderQueryParam.merchantOrderNo}" />
					&nbsp;&nbsp;
					银行订单号：
					<input type="text" id="bankOrderNo" name="bankOrderNo" value="${paymentOrderQueryParam.bankOrderNo}">
					&nbsp;&nbsp;
					支付流水号：
					<input type="text" id="trxNo" name="trxNo" value="${paymentOrderQueryParam.trxNo}">
					</td>
				</tr>
				<%-- 
					<td colspan="2">
						商户编号：
						<input type="text" id="merchantNo" name="merchantNo" value="${paymentOrderQueryParam.merchantNo}" />
						&nbsp;&nbsp;
						商户订单号：
						<input type="text" id="merchantOrderNo" name="merchantOrderNo" value="${paymentOrderQueryParam.merchantOrderNo}" />
						&nbsp;&nbsp;
						银行订单号：
						<input type="text" id="bankOrderNo" name="bankOrderNo" value="${paymentOrderQueryParam.bankOrderNo}">
						&nbsp;&nbsp;
						支付流水号：
						<input type="text" id="trxNo" name="trxNo" value="${paymentOrderQueryParam.trxNo}">
					</td>
				--%>
				
				<tr>
					<td colspan="2">
						下单时间：<input type="text" size="16" id="recordDateBegin" name="orderDateBegin" datefmt="yyyy-MM-dd HH:mm:ss" value="${paymentOrderQueryParam.orderDateBegin}" class="date textInput readonly valid" readonly="true">
						到&nbsp;<input type="text" size="16" id="recordDateEnd" name="orderDateEnd" datefmt="yyyy-MM-dd HH:mm:ss" value="${paymentOrderQueryParam.orderDateEnd}" class="date textInput readonly valid" readonly="true">
						[&nbsp;<a href="javascript:void(0);" onclick="selectPaymentRecordDate('today');" style="color:blue;">今天</a>&nbsp;]
						[&nbsp;<a href="javascript:void(0);" onclick="selectPaymentRecordDate('yesterday');" style="color:blue;">昨天</a>&nbsp;]
						[&nbsp;<a href="javascript:void(0);" onclick="selectPaymentRecordDate('clean');" style="color:blue;">清除</a>&nbsp;]
						&nbsp;&nbsp;&nbsp;&nbsp;
						支付时间：<input type="text" size="16" id="payTimeBegin" name="payTimeBegin" datefmt="yyyy-MM-dd HH:mm:ss" value="${paymentOrderQueryParam.payTimeBegin}" class="date textInput readonly valid" readonly="true">
						到&nbsp;<input type="text" size="16" id="payTimeEnd" name="payTimeEnd" datefmt="yyyy-MM-dd HH:mm:ss" value="${paymentOrderQueryParam.payTimeEnd}" class="date textInput readonly valid" readonly="true">
						[&nbsp;<a href="javascript:void(0);" onclick="selectPayTime('today');" style="color:blue;">今天</a>&nbsp;]
						[&nbsp;<a href="javascript:void(0);" onclick="selectPayTime('yesterday');" style="color:blue;">昨天</a>&nbsp;]
						[&nbsp;<a href="javascript:void(0);" onclick="selectPayTime('clean');" style="color:blue;">清除</a>&nbsp;]
					</td>
				</tr>
				
				<tr>
					<td>
						交易状态：
						<select id="status" name="status">
							<option value="">请选择</option>
							<c:forEach items="${statusEnums}" var="statusVar">
								<option value="${statusVar.key}" <c:if test="${paymentOrderQueryParam.status == statusVar.key}"> selected="selected"</c:if>>${statusVar.value.desc}</option>
							</c:forEach>
						</select>
						&nbsp;&nbsp;
						支付方式：
						<select id="payWayName" name="payWayName">
							<option value="">请选择</option>
							<c:forEach items="${payWayNameEnums}" var="payWayNameVar">
								<option value="${payWayNameVar.value.desc}" <c:if test="${paymentOrderQueryParam.payWayName == payWayNameVar.value.desc}"> selected="selected"</c:if>>${payWayNameVar.value.desc}</option>
							</c:forEach>
						</select>
						&nbsp;&nbsp;
						支付类型：
						<select id="payTypeName" name="payTypeName">
							<option value="">请选择</option>
							<c:forEach items="${payTypeNameEnums}" var="payTypeNameVar">
								<option value="${payTypeNameVar.value.desc}" <c:if test="${paymentOrderQueryParam.payTypeName == payTypeNameVar.value.desc}"> selected="selected"</c:if>>${payTypeNameVar.value.desc}</option>
							</c:forEach>
						</select>
						&nbsp;&nbsp;
						结算状态：
						<select id="settStatus" name="settStatus">
							<option value="">请选择</option>
							<c:forEach items="${tradeSettStatusEnums}" var="settStatusVar">
								<option value="${settStatusVar.key}" <c:if test="${paymentOrderQueryParam.settStatus == settStatusVar.key}"> selected="selected"</c:if>>${settStatusVar.value.desc}</option>
							</c:forEach>
						</select>
						&nbsp;&nbsp;
						结算类型：
						<select id="settType" name="settType">
							<option value="">请选择</option>
							<c:forEach items="${bankSettTypeEnums}" var="settTypeVar">
								<option value="${settTypeVar.key}" <c:if test="${paymentOrderQueryParam.settType == settTypeVar.key}"> selected="selected"</c:if>>${settTypeVar.value.desc}</option>
							</c:forEach>
						</select>
						&nbsp;&nbsp;
						通道名称：
						<select id="bankWayName" name="bankWayName">
							<option value="">请选择</option>
							<c:forEach items="${bankWayEnums}" var="bankWayNameVar">
								<option value="${bankWayNameVar.key}" <c:if test="${paymentOrderQueryParam.bankWayName == bankWayNameVar.key}"> selected="selected"</c:if>>${bankWayNameVar.value.desc}</option>
							</c:forEach>
						</select>
						<%--
						资金流入类型：
						<select name="fundIntoType">
							<option value="">请选择</option>
							<c:forEach items="${fundIntoTypeEnums}" var="fundIntoTypeVar">
								<option value="${fundIntoTypeVar.key}" <c:if test="${paymentOrderQueryParam.fundIntoType == fundIntoTypeVar.key}"> selected="selected"</c:if>>${fundIntoTypeVar.value.desc}</option>
							</c:forEach>
						</select>
						--%>
					</td>
					<td>
						<div class="buttonActive">
							<div class="buttonContent">
								<button title="查询" type="submit">查&nbsp;询</button>
							</div>
						</div>
					</td>
				</tr>
			</table>
		</div>
	</form>
</div>
<div class="pageContent">
	<div class="panelBar">
		<ul class="toolBar">
			<shiro:hasPermission name="sum:paySum:view">
				<li>
					<span> 
						【支付记录总数：
						<!--<font color="red" id="tradeCount"></font>&nbsp;条-->
						
						<c:if test="${countResultMap.successAll eq null}">
							<font color="red">0</font>&nbsp;条
						</c:if>
						<c:if test="${countResultMap.successAll ne null}">
							<font color="red">${countResultMap.successAll}</font>&nbsp;条
						</c:if>】
						【订单总金额：
						<!--<font color="red" id="tradeOrderAmount"></font>&nbsp;元-->
						
						<c:if test="${countResultMap.sumOrderAmount eq null}">
							<font color="red">0</font>&nbsp;元
						</c:if> 
						<c:if test="${countResultMap.sumOrderAmount ne null}">
							<font color="red"><fmt:formatNumber value="${countResultMap.sumOrderAmount}" pattern="#0.00" /></font>&nbsp;元
						</c:if>】
						【平台毛利润：
						<!--<font color="red" id="tradePlatIncome"></font>&nbsp;元-->
						
						<c:if test="${countResultMap.sumPlatIncome eq null}">
							<font color="red">0</font>&nbsp;元
						</c:if>
						<c:if test="${countResultMap.sumPlatIncome ne null}">
							<font color="red"><fmt:formatNumber value="${countResultMap.sumPlatIncome}" pattern="#0.00" /></font>&nbsp;元
						</c:if>】
						【平台成本：
						<!--<font color="red" id="tradePlatCost"></font>&nbsp;元-->
						
						<c:if test="${countResultMap.sumPlatCost eq null}">
							<font color="red">0</font>&nbsp;元
						</c:if> 
						<c:if test="${countResultMap.sumPlatCost ne null}">
							<font color="red"><fmt:formatNumber value="${countResultMap.sumPlatCost}" pattern="#0.00" /></font>&nbsp;元
						</c:if>】
						【平台纯收益：
						<!--<font color="red" id="tradePlatProfit"></font>&nbsp;元-->
						
						<c:if test="${countResultMap.sumPlatProfit eq null}">
							<font color="red">0</font>&nbsp;元
						</c:if> 
						<c:if test="${countResultMap.sumPlatProfit ne null}">
							<font color="red"><fmt:formatNumber value="${countResultMap.sumPlatProfit}" pattern="#0.00" /></font>&nbsp;元
						</c:if>】
					</span>
				</li> 
			</shiro:hasPermission>
		</ul>
	</div>
	<table class="table" width="2000" layoutH="162">
		<thead>
			<tr>
				<th width="36">序号</th>
				<th width="130">创建时间</th>
				<th width="130">支付时间</th>
				<th width="200">商户编号 / 商户名称</th>
				<th width="150">商户订单号</th>
				<th width="180">银行订单号</th>
				<th width="70">订单金额</th>
				<th width="60">支付状态</th>
				<!-- <th width="60">业务类型</th> -->
				<th width="100">支付方式</th>
				<shiro:hasPermission name="sum:paySum:view">
					<th width="60">平台收入</th>
					<th width="60">平台成本</th>
					<th width="60">平台利润</th>
				</shiro:hasPermission>
				<th width="180">支付流水号</th>
				<th width="180">结算商户编号</th>
				<th width="60">结算状态</th>
				<th>结算类型</th>
				<th>支付渠道编号</th>
				<th>通道名称</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach var="item" items="${pageBean.recordList}" varStatus="s">
				<tr>
					<td>${s.index + 1}</td>
					<td>
						<fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm:ss" />
					</td>
					<td>
						<fmt:formatDate value="${item.paySuccessTime}" pattern="yyyy-MM-dd HH:mm:ss" />
					</td>
					<td>${item.merchantNo}<br/>${item.merchantName}</td>
					<td>${item.merchantOrderNo}</td>
					<td>${item.bankOrderNo}</td>
					<td>
						<fmt:parseNumber type="number" pattern="#,#00.0#">${item.orderAmount}</fmt:parseNumber>
					</td>
					<td>
						<c:forEach items="${statusEnums}" var="statusVar">
							<c:if test="${item.status == statusVar.key}">
								<c:if test="${item.status == 'SUCCESS' || item.status == 'FINISH'}">
									<font color="blue">${statusVar.value.desc}</font>
								</c:if>
								<c:if test="${item.status != 'SUCCESS' && item.status != 'FINISH'}">
									<font color="gray">${statusVar.value.desc}</font>
								</c:if>
							</c:if>
						</c:forEach>
					</td>
					<%-- 
					<td>
						<c:forEach items="${trxTypeEnums}" var="trxTypeVar">
							<c:if test="${item.trxType == trxTypeVar.key}">${trxTypeVar.value.desc}</c:if>
						</c:forEach>
					</td> 
					--%>
					<td><%-- ${item.payWayName}<br /> --%>${item.payTypeName}</td>
					<shiro:hasPermission name="sum:paySum:view">
						<td>
							<fmt:parseNumber type="number" pattern="#,#00.0#">${item.platIncome}</fmt:parseNumber>
						</td>
						<td>
							<fmt:parseNumber type="number" pattern="#,#00.0#">${item.platCost}</fmt:parseNumber>
						</td>
						<td>
							<fmt:parseNumber type="number" pattern="#,#00.0#">${item.platProfit}</fmt:parseNumber>
						</td>
					</shiro:hasPermission>
					
					<td>${item.trxNo}</td>
					<td>${item.settMerchantNo}</td>
					<td>
						<c:forEach items="${tradeSettStatusEnums}" var="settStatusVar">
							<c:if test="${item.settStatus == settStatusVar.key}">${settStatusVar.value.desc}</c:if>
						</c:forEach>
					</td>
					<td>${item.settType}</td>
					<td>${item.bankChannelCode}</td>
					<td>${item.bankWayName}</td>
					<td>
						<a target="ajaxTodo" href="${baseURL }/trade/recordNotify/${item.merchantNo}/${item.merchantOrderNo}/${item.bankOrderNo}/${item.status}" style="color: blue;">查补通知</a>
					</td>
				</tr>
			</c:forEach>
			<c:if test="${pageBean.totalCount==0}">
				<tr>
					<td>暂无数据</td>
				</tr>
			</c:if>
		</tbody>
	</table>
	<%@include file="../common/pageBar.jsp"%>
</div>
<script type="text/javascript">
//获取订单日期
function selectPaymentRecordDate(param){
	if(param == null || param == ""){
		return;
	}
	if(param == "today"){
		// 获取当天的日期
		var clock = getDateStr(0);
        $("#recordDateBegin").val(clock + " 00:00:00");
        clock = getDateStr(0);
        $("#recordDateEnd").val(clock + " 23:59:59");
	}else if (param == "yesterday"){
		// 昨天
		var clock = getDateStr(-1);
        $("#recordDateBegin").val(clock + " 00:00:00");
        clock = getDateStr(-1);
        $("#recordDateEnd").val(clock + " 23:59:59");
	}else if (param == "clean"){
		// 清空时间
        $("#recordDateBegin").val("");
        $("#recordDateEnd").val("");
	}
}

//获取支付时间
function selectPayTime(param){
	if(param == null || param == ""){
		return;
	}
	if(param == "today"){
		// 获取当天的日期
		var clock = getDateStr(0);
        $("#payTimeBegin").val(clock + " 00:00:00");
        clock = getDateStr(0);
        $("#payTimeEnd").val(clock + " 23:59:59");
	}else if (param == "yesterday"){
		// 昨天
		var clock = getDateStr(-1);
        $("#payTimeBegin").val(clock + " 00:00:00");
        clock = getDateStr(-1);
        $("#payTimeEnd").val(clock + " 23:59:59");
	}else if (param == "clean"){
		// 清空时间
        $("#payTimeBegin").val("");
        $("#payTimeEnd").val("");
	}
}

// 格式化日期
function getDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m = dd.getMonth()+1;//获取当前月份的日期
    var d = dd.getDate();
    if(m < 10){
    	m = "0" + m;
    }
    if(d < 10){
    	d = "0" + d;
    }
    return y+"-"+m+"-"+d;
}

/** 异步统计交易数据 **/
/**
function sumAmountTrade(){
	$("#tradeCount").html("");
	$("#tradeOrderAmount").html("");
	$("#tradePlatIncome").html("");
	$("#tradePlatCost").html("");
	$("#tradePlatProfit").html("");
	var merchantNo = $("#merchantNo").val();
	var merchantOrderNo = $("#merchantOrderNo").val();
	var bankOrderNo = $("#bankOrderNo").val();
	var trxNo = $("#trxNo").val();
	var recordDateBegin = $("#recordDateBegin").val();
	var recordDateEnd = $("#recordDateEnd").val();
	var payTimeBegin = $("#payTimeBegin").val();
	var payTimeEnd = $("#payTimeEnd").val();
	var status = $("#status").val();
	var payWayName = $("#payWayName").val();
	var payTypeName = $("#payTypeName").val();
	var settStatus = $("#settStatus").val();
	$.ajax({  
        type: "GET",
        data : {
        	merchantNo : merchantNo,
        	merchantOrderNo : merchantOrderNo,
        	bankOrderNo : bankOrderNo,
        	trxNo : trxNo,
        	recordDateBegin : recordDateBegin,
        	recordDateEnd : recordDateEnd,
        	payTimeBegin : payTimeBegin,
        	payTimeEnd : payTimeEnd,
        	status : status,
        	payWayName : payWayName,
        	payTypeName : payTypeName,
        	settStatus : settStatus
		},
        dataType:'json',
        timeout:20000,
        url: "${baseURL }/trade/sumAmountTrade",
        //请求成功完成后要执行的方法  
        success: function(result){
        	$("#tradeCount").html(result.successAll);
        	$("#tradeOrderAmount").html(result.sumOrderAmount);
        	$("#tradePlatIncome").html(result.sumPlatIncome);
        	$("#tradePlatCost").html(result.sumPlatCost);
        	$("#tradePlatProfit").html(result.sumPlatProfit);
        },  
        error : function() {
        	 alert("统计数据超时，请稍后再试");
        }   
    });
}

window.setTimeout(sumAmountTrade,2000); 
**/
</script>